package com.bgs.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class DirectConfig {
    //交换机
    public static final String DIRECT_EXCHANGE_NAME = "direct.test.exchange";
    //绑定的key
    public static final String DIRECT_EXCHANGE_ROUTING_KEY = "direct.text.routing.key";
    //队列
    public static final String DIRECT_EXCHANGE_QUEUE = "direct.test.queue";

    @Bean
    public DirectExchange directExchange() {
        DirectExchange exchange = new DirectExchange(DIRECT_EXCHANGE_NAME, false, true);
        return exchange;
    }

    @Bean
    public Queue directQueue() {
        Queue queue = new Queue(DIRECT_EXCHANGE_QUEUE, true, false, false);
        return queue;
    }

    @Bean
    public Binding directBinding() {
        Binding binding = BindingBuilder.bind(directQueue()).to(directExchange()).with(DIRECT_EXCHANGE_ROUTING_KEY);
        return binding;
    }
}